package com.example.thread.d7ThreadTest;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class ThreadTest {
    public static void main(String[] args) throws Exception {
        // 有100份礼物，小红，小明两人同时发送，当剩下的礼品小于10份的时候则不再送出，
        // 利用多线程模拟该过程并将线程的名称打印出来，并最后在控制台分别打印小红，小明各自送出多少份礼物
        List<String> gift = new ArrayList<>();
        String[] names = {"口红","包包","鲜花","手表","皮带"};
        Random r = new Random();
        for (int i = 0; i < 10000; i++) {
            gift.add(names[r.nextInt(names.length)]+(i+1));
        }
        System.out.println(gift);

        SendThread xm = new SendThread(gift, "xm");
        xm.start();
        xm.join();

        SendThread xh = new SendThread(gift, "xh");
        xh.start();
        xh.join();

        System.out.println(xm.getCount());
        System.out.println(xh.getCount());
    }
}
